﻿using System.Web.UI.WebControls;
using EPiServer.DataAbstraction;

namespace TemplateFoundation.UI.WebControls
{
    /// <summary>
    /// Used to add a text box when creating user interfaces for the EPiServer UI
    /// </summary>
    public class TextBox : PagePropertyStyleControlBase
    {
        private readonly System.Web.UI.WebControls.TextBox _textBox;

        /// <summary>
        /// Creates a new TextBox
        /// </summary>
        public TextBox()
        {
            base.Name = "Text";
            base.Description = "Enter text";

            _textBox = new System.Web.UI.WebControls.TextBox
                           {
                               TextMode = TextBoxMode.SingleLine
                           };
        }

        /// <summary>
        /// Creates the property control to render
        /// </summary>
        /// <returns></returns>
        public override System.Web.UI.Control CreatePropertyControl()
        {
            return _textBox;
        }

        /// <summary>
        /// Gets or sets the type of text box to render
        /// </summary>
        public TextBoxMode TextMode
        {
            get
            {
                return _textBox.TextMode;
            }
            set
            {
                _textBox.TextMode = value;
            }
        }

        /// <summary>
        /// Gets or sets the text of the text box
        /// </summary>
        public string Text
        {
            get
            {
                return _textBox.Text;
            }
            set
            {
                _textBox.Text = value;
            }
        }

        /// <summary>
        /// Gets the client ID of the value control
        /// </summary>
        public string ValueControlId
        {
            get
            {
                return _textBox.ClientID;
            }
        }
    }
}
